import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:smart_shop/components/shop_search_bar.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    _getHomeData();
  }

  void _getHomeData() async {
    // 1.创建dio对象
    final dio = Dio();
    final res = await dio
        .get('http://smart-shop.itheima.net/index.php?s=/api/page/detail');
    print(res.data);

    // 3. .setState 更新状态
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.pink,
        foregroundColor: Colors.white,
        centerTitle: true,
        title: const Text('智慧商城'),
      ),
      body: const CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: ShopSearchBar(),
          )
        ],
      ),
    );
  }
}
